<?php
            


/**
 * 业务逻辑封装
 * 使用tablename()函数不要忘记引入define.php,同时需要在define.php中需要定义好表别名
 */
require_once PATH_MODULE .'define.php';
class DemoModel extends PluginModel
{
    /**
     * @param $themeid
     * @param int $type
     * @param int $page_start
     * @param int $page_size
     * @return mixed
     */
    public static function demo1($themeid, $type = 0, $page_start = 0, $page_size = 10)
    {
        $condition = "";
        if ($type) {
            $condition .= " and a.type='" . $type . "'";
        }

        $page_index = max(1,intval($_P['page']));
        $page_size = 50;
        $page_start = ($page_index-1)*$page_size;

        $search_data = isset($_P['search_data'])?$_P['search_data']:'';
        if ($search_data){
            $search = '%'.$search_data.'%';
            $condition .= " AND (b.nickname LIKE '" . $search . "'" . " or b.mobile LIKE '" . $search . "' " . " or a.convert_code LIKE '" . $search . "') ";
        }

        $condition .= " order by a.created_at desc ";
        if ($page_size) {
            $condition .= "  limit " . $page_start . "," . $page_size;
        }

        $sql = " select a.*,b.id as fan_id,b.username,b.avatar,b.nickname,b.username,b.jihui,b.mobile,c.nickname as from_nickname  from " . tablename(t_develop_demo) . " as a " .
            "left join " . tablename(t_fans) . " as b on b.uid = a.uid and b.themeid=$themeid" .
            " left join " . tablename(t_fans) . " as c on a.from_uid = c.uid and c.themeid=$themeid" .
            " where a.themeid=$themeid  " . $condition;
        return db_select($sql);
    }
}